Title: Add an Empty Cart Button in WooCommerce

Publish Date: Sat, 01 Sep 2018 07:00:00 +0000

Categories: Uncategorized

Content:

Adding an Empty Cart button to your store might look like a bad idea. Why would you want to make easier for your customers to empty the cart with one click? You don't want them to leave without buying!



Do you know what is even worse than that? Having a grumpy customer. If the customer doesn't want to buy it's not a missing Empty Cart button that will make the difference.



So make their life easier and add it.









Open your functions.php file in wp-content/themes/your-child-theme-name/ and add this code at the end of the file:




https://gist.github.com/SiR-DanieL/4442c0fc301b8253e26a31666bb14314




This code adds the button right after the Apply Coupon button on the Cart page.







Of course, just the button alone is not enough. You need to add some more code right after the previous one:




https://gist.github.com/SiR-DanieL/46ab54c2f270397be244cd385bd969a3




This is the logic that handles the Empty Cart button, and removes all the products at once, redirecting to the cart page again.



Creating a custom Empty Cart button



With this code in place, you can also create a custom button or a simple link to empty the cart. Just get any link
	in your site and add the
	parameter ?empty_cart=yes
	 to it.



Here are two different examples:




https://domain.com/product/awesome-product/?empty_cart=yes



https://domain.com/?utm=something&empty_cart=yes﻿
